package demo1.servlet.userMai;

import com.alibaba.fastjson.JSON;
import demo1.pojo.goods;
import demo1.pojo.tableData;
import demo1.pojo.users;
import demo1.service.goodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/deleteGoods")
public class deleteGoods extends HttpServlet {//批量删除商品
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {//删除商品
        //接受数据
        BufferedReader br = req.getReader();
        String params = br.readLine();//json字符串

        //转为goods对象
        int[] ids = JSON.parseObject(params, int[].class);

        goodsService goodsService = new goodsService();
        try {
            int num = goodsService.deleteGoods(ids);
            if (num == 1) {
                //删除成功
                resp.getWriter().write("success");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
